package com.google.common.primitives;

import com.google.common.base.Preconditions;
import javax.annotation.CheckReturnValue;
import javax.annotation.Nullable;

public final class UnsignedInteger extends Number implements Comparable<UnsignedInteger> {
    public static final UnsignedInteger MAX_VALUE = asUnsigned(-1);
    public static final UnsignedInteger ONE = asUnsigned(1);
    public static final UnsignedInteger ZERO = asUnsigned(0);
    private final int value;

    private UnsignedInteger(int value) {
        this.value = value & -1;
    }

    @Deprecated
    public static UnsignedInteger asUnsigned(int value) {
        return fromIntBits(value);
    }

    public static UnsignedInteger fromIntBits(int bits) {
        return new UnsignedInteger(bits);
    }

    public static UnsignedInteger valueOf(long value) {
        boolean z;
        if ((4294967295L & value) == value) {
            z = true;
        } else {
            z = false;
        }
        Preconditions.checkArgument(z, "value (%s) is outside the range for an unsigned integer value", Long.valueOf(value));
        return fromIntBits((int) value);
    }

    @CheckReturnValue
    public UnsignedInteger plus(UnsignedInteger val) {
        return fromIntBits(((UnsignedInteger) Preconditions.checkNotNull(val)).value + this.value);
    }

    @CheckReturnValue
    public UnsignedInteger minus(UnsignedInteger val) {
        return fromIntBits(this.value - ((UnsignedInteger) Preconditions.checkNotNull(val)).value);
    }

    @CheckReturnValue
    public UnsignedInteger times(UnsignedInteger val) {
        return fromIntBits(((UnsignedInteger) Preconditions.checkNotNull(val)).value * this.value);
    }

    @CheckReturnValue
    public UnsignedInteger dividedBy(UnsignedInteger val) {
        return fromIntBits(UnsignedInts.divide(this.value, ((UnsignedInteger) Preconditions.checkNotNull(val)).value));
    }

    public int intValue() {
        return this.value;
    }

    public long longValue() {
        return UnsignedInts.toLong(this.value);
    }

    public float floatValue() {
        return (float) longValue();
    }

    public double doubleValue() {
        return (double) longValue();
    }

    public int compareTo(UnsignedInteger other) {
        Preconditions.checkNotNull(other);
        return UnsignedInts.compare(this.value, other.value);
    }

    public int hashCode() {
        return this.value;
    }

    public boolean equals(@Nullable Object obj) {
        if (!(obj instanceof UnsignedInteger)) {
            return false;
        }
        if (this.value == ((UnsignedInteger) obj).value) {
            return true;
        }
        return false;
    }

    public String toString() {
        return toString(10);
    }

    public String toString(int radix) {
        return UnsignedInts.toString(this.value, radix);
    }
}
